package com.example.demo.service.warehouse;


import com.example.demo.dao.warehouse.ProductDAO;
import com.example.demo.model.warehouse.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class ProductService {
    @Autowired
    private ProductDAO dao;

    public Boolean save(Product product) {
        Boolean flag = false;

        if (product.getProduct_id() != null) {
            flag = dao.updateById(product) == 1;
        } else {
            flag = dao.addProduct(product) == 1;
        }

        return flag;
    }

    //    查询全部
    public List<Product> selectAll() {
        return dao.selectAll();
    }

    //    添加数据
    public Integer addProduct(Product product) {
        return dao.addProduct(product);
    }

    //删除数据
    public Integer deleteById(Integer product_id) {
        return dao.deleteById(product_id);
    }

    //更新
    public Integer updateById(Product product) {
        return dao.updateById(product);
    }

    //根据id更新状态
    public Integer updateStatusById(Integer product_id) {
        return dao.updateStatusById(product_id);
    }

    public List<Product> findProduct(String product_name, Integer id, Integer product_model, Integer product_unit) {
        return dao.findProduct(product_name, id, product_model, product_unit);
    }


    public List<Product> All() {
        return dao.All();
    }
}
